< previous page page_104 next page >

Page 104
      txtOneLine.BackColor = WHITE
      txtOneLine.ForeColor = BLUE
   End If
End Sub
Now, add the following code to the Custom button:
Sub cmdCustom_Click ()
   SetColors 1
End Sub
Save and run the program to see the results. Not such a good color scheme, you say? Well, some may like your custom setting; some may want to keep the default setting. Now you can select the scheme you want with a click of the mouse!
System Colors
As you can see in the previous code example, some color schemes can be less than perfect. Many programmers add routines to allow users to customize the color scheme to their own taste. The easiest way to do this is to let Windows set the color scheme for you. The code example that follows uses the color scheme selected through the Windows 95 Display applet. This is an excellent way to give your users the power to customize their application color without writing a lot of Visual Basic code.
There are several Windows constants for the system colors that are set by the Control Panel program. For this example, you'll use only three. The following code shows a modified declaration section with the Windows system color constants added:
Option Explicit
'
' constant for colors
Const LIGHT_GRAY = &HC0C0C0
Const WHITE = &HFFFFFF
Const BLACK = &H0
Const BLUE = &H800000
Const RED = &H80
'
' windows system color values
Const WINDOW_BACKGROUND = &H80000005     ' Window background.
Const WINDOW_TEXT = &H80000008           ' Text in windows.
Const APPLICATION_WORKSPACE = &H8000000C ' Background color of MDI apps
Next, you'll add code to the SetColors routine that sets the colors to the Windows system colors.
Sub SetColors (nSet As Integer)
   '
   ' set to default colors
   If nSet = 0 Then
      pnlDisplayOnly.BackColor = LIGHT_GRAY
      pnlPalette.BackColor = LIGHT_GRAY

 
< previous page page_104 next page >

If you like this book, buy it!